<?php
	//include_once('verifica.php');
	include_once('config/class.pdo.php');
	
	//print_r($_POST[id]);
	if(isset($_POST['id'])) {
		$pdo = new DB;	
		$pdo-> conexao();
		
		$Query = 'SELECT 
					nomeUsuario,
					email,
					login,
					senha,
					dataCadastroUsuario,
					ativo,
					idusuario
				  FROM usuario 
		WHERE idusuario = '.$_POST['id'].'';
		$result = $pdo->oneReg($Query);				
		//print_r($result);
	} 			
?>
<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="stylesheet" href="css/jquery-ui.css" />
		<link rel="stylesheet" href="css/style.css" />
		<script type="text/javascript" src="js/jquery-1.9.1.js" ></script>
		<script type="text/javascript" src="js/jquery-ui.js" ></script>	
		<script type="text/javascript" src="js/jquery.maskedinput.js" ></script>		
		<script type="text/javascript" src="js/jquery.validate.js" ></script>
		<script type="text/javascript" src="js/jsCadUsuario.js"></script>	
		<script type="text/javascript" src="js/funcoes.js"></script>			
	</head>	
	<body style="font-size:10px;">
		<form name="frmUsuario" id="frmUsuario" method="POST">
			<div id="divUsuario" class="divUsuario">
				<fieldset class="backFieldset">
					<legend> <b> Cadastro de Usuários </b> </legend>
					<table class="table">
						<?php 
							if(isset($_POST['id'])) {
								echo '<tr>';
								echo '<td> Código: </td>';
								echo '<td colspan=0> <input type="text" name="cu_id" id="cu_id" value="'.$result['idusuario'].'" readonly /> </td>';
								echo '<td> Cadastro: </td>';
								echo '<td colspan=0> <input type="text" name="cu_dataCadastro" id="cu_dataCadastro" value="'.$result['dataCadastroUsuario'].'" readonly /> </td>';
								echo '</tr>';
							}
						?>
						<tr>
							<td width=100> Nome: </td>
							<td colspan=3> <input type="text" name="cu_nome" id="cu_nome" class="input-xxlarge" title="Campo NOME deve ser preenchido." value="<?php echo utf8_encode(@$result['nomeUsuario']); ?>" required /> </td>
						</tr>
						<tr>
							<td> E-Mail: </td>
							<td colspan=3> <input type="email" name="cu_email" id="cu_email" class="input-xxlarge" title="Campo E-MAIL deve ser preenchido." value="<?php echo utf8_encode(@$result['email']); ?>" /> </td>
						</tr>
						<tr>
							<td> Login: </td>
							<td colspan=0 width=260> <input type="text" name="cu_login" id="cu_login" class="input-large" title="Campo LOGIN deve ser preenchido." value="<?php echo utf8_encode(@$result['login']); ?>" required /> </td>
							<?php 
								if(isset($_POST['id'])) {	
									if ($result['ativo'] == '1') {
										echo '<td> Status: </td>';
										echo '<td colspan=0> <select id="cu_ativo" name="cu_ativo"> <option value="1" selected> Ativo </option> <option value="2"> Inativo </option> </select>';							
									} else {
										echo '<td> Status: </td>';
										echo '<td colspan=0> <select id="cu_ativo" name="cu_ativo"> <option value="1"> Ativo </option> <option value="2" selected> Inativo </option> </select>';							
									}
								}
							?>
                            <td colspan=2> <input type="checkbox" name="cu_ativo" id="cu_ativo" value="0"> Ativo </td>  
						</tr>
						<tr>
							<td> Senha: </td>
							<td colspan=0> <input type="password" name="cu_senha" id="cu_senha" title="Campo SENHA deve ser preenchido." onkeydown = "BloqueiaComando(event)" onpaste="return false;" value="<?php echo @$result['senha']; ?>" size="100" required /> </td>
							<td width=100> Confirmação: </td>
							<td colspan=0> <input type="password" name="cu_confirmacao" id="cu_confirmacao" title="Campo CONFIRMAÇÃO deve ser preenchido." onkeydown = "BloqueiaComando(event)" onpaste="return false;" size="100" required /> </td>
						</tr>
					</table>
				</fieldset>
			</div>
			<?php
				echo '<table>';
					echo '<tr>';
						if(isset($_POST['id'])) {
							echo '<td> <button type="submit" name="atualizar" class="btn btn-success"> <i class="icon-refresh"></i> Atualizar </button>'; 
							echo '    <button type="button" name="cancelar" onclick="apagaForm()" class="btn btn-danger" > <i class="icon-ban-circle"></i> Cancelar </button>';
							echo '    <button type="button" name="voltar" id="voltar" onclick="loadPage(19);" class="btn btn-primary" > <i class="icon-arrow-left"></i> Voltar </button> <input type="hidden" id="controle" value="atualizar"> </td>';
						} else {
							echo '<td> <button type="submit" name="gravar" class="btn btn-success"> <i class="icon-ok"></i> Gravar </button>'; 
							echo '    <button type="button" name="cancelar" onclick="apagaForm()" class="btn btn-danger" > <i class="icon-ban-circle"></i> Cancelar </button>';
							echo '    <button type="button" name="sair" id="sair" onclick="loadPage(1);" class="btn btn-primary" > <i class="icon-home"></i> Sair </button> <input type="hidden" id="controle" value="gravar"> </td>';
						}
					echo '</tr>';
				echo '</table>';
			?>
		</form>
		<div id="retornoUsuario"> </div>
		<div class="container">
				<h4>Favor preencha os campos abaixo citados:</h4>
				<ol>					
				</ol>
		</div>
	</body>
</html>